<template>
  <div id="main" style="width: 900px; height: 850px"></div>
</template>

<script>
import * as echarts from 'echarts'
export default {
  props: {
    datas: Array,
    title1:String,
    title2:String
  },
  data() {
    return {
      options: {},
      charts: "",
    };
  },
  mounted() {
    this.options = {
      dataset: {
        source: this.datas,
        
      },
      // Make gradient line here
      visualMap: [
        {
          show: false,
          type: "continuous",
          seriesIndex: 0,
          min: 0,
          max: 400,
        },
        {
          show: false,
          type: "continuous",
          seriesIndex: 1,
          dimension: 0,
          min: 0,
          max: this.datas[0].length - 1,
        },
      ],

      title: [
        {
          left: "center",
          text: this.title1,
        },
        {
          top: "55%",
          left: "center",
          text: this.title2
        },
      ],
      tooltip: {
        trigger: "axis",
      },
      xAxis: [
        {
            type: 'category',
        //   data: dateList,
        },
        {
            type: 'category',
        //   data: dateList,
          gridIndex: 1,
        },
      ],
      yAxis: [
        {},
        {
          gridIndex: 1,
        },
      ],
      grid: [
        {
          bottom: "60%",
        },
        {
          top: "60%",
        },
      ],
      series: [
        {
          type: "line",
          showSymbol: false,
          seriesLayoutBy: "row",
          encode:{
              x:'source_date',
              y:'source',
          }
        },
        {
          type: "line",
          showSymbol: false,
          seriesLayoutBy: "row",
          encode:{
              x:'source_date',
              y:'train',
          }
        },
        {
          type: "line",
          showSymbol: false,
          seriesLayoutBy: "row",
          xAxisIndex: 1,
          yAxisIndex: 1,
          encode:{
              x:'MA_date',
              y:'MA'
          }
        },
      ],
      legend: {
        show: true,
      },
    };
    this.charts=echarts.init(document.getElementById("main"))
    this.charts.setOption(this.options)
  },
  watch:{
      datas:{
          handler(nd){
              this.options.dataset.source=nd
              this.charts.setOption(this.options)
          },
          deep:true
      }
  }
};
</script>

<style>
</style>